package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.ServiceCenterAudit;
import com.sc.nft.entity.dto.ServiceCenterAuditDTO;
import com.sc.nft.entity.vo.ServiceCenterAuditVO;
import com.sc.nft.mapper.ServiceCenterAuditMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * (ServiceCenterAudit)表Dao层
 *
 * @author wwc
 * @since 2023-07-18 14:40:10
 */
@Slf4j
@Repository
public class ServiceCenterAuditDao extends ServiceImpl<ServiceCenterAuditMapper, ServiceCenterAudit> {

    public Page<ServiceCenterAuditVO> compactPage(Page page, ServiceCenterAuditDTO serviceCenterAuditDTO) {
        return baseMapper.compactPage(page, serviceCenterAuditDTO);
    }

    public ServiceCenterAudit getOneByUserId(Long userId) {
        LambdaQueryWrapper<ServiceCenterAudit> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getUserId, userId);
        return baseMapper.selectOne(objectLambdaQueryWrapper);
    }

    public ServiceCenterAudit getOneByUserIdAndType(Long userId,Integer type) {
        LambdaQueryWrapper<ServiceCenterAudit> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getUserId,userId);
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getType,type);
        return baseMapper.selectOne(objectLambdaQueryWrapper);
    }

    public ServiceCenterAudit getByIdAndType(Long id, Integer type) {
        LambdaQueryWrapper<ServiceCenterAudit> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getId, id);
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getType, type);
        return baseMapper.selectOne(objectLambdaQueryWrapper);
    }
    public ServiceCenterAudit getByUserIdAndType(Long userId, Integer type) {
        LambdaQueryWrapper<ServiceCenterAudit> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getUserId, userId);
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getType, type);
        return baseMapper.selectOne(objectLambdaQueryWrapper);
    }

    public void cancelCommunityOutletsRecord(Long userId,Integer type) {
        LambdaQueryWrapper<ServiceCenterAudit> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getUserId, userId);
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getType, type);
        baseMapper.delete(objectLambdaQueryWrapper);
    }

    public void deleteByUserId(Long userId,Integer type) {
        LambdaQueryWrapper<ServiceCenterAudit> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getUserId, userId);
        objectLambdaQueryWrapper.eq(ServiceCenterAudit::getType, type);
        baseMapper.delete(objectLambdaQueryWrapper);
    }
}
